package com.webserver.core;

import java.net.ServerSocket;
import java.net.Socket;

/**
 * Author：毕龙
 * Date: 2022/9/21 8:35
 * Web server web容器
 * 用于实现tomcat
 */
public class WebServerApplication {
    private ServerSocket serverSocket;

    public WebServerApplication(){
        try {
            System.out.println("正在启动服务器....");
            serverSocket = new ServerSocket(8088);
            System.out.println("服务端启动完毕！！");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void start(){
        try {
            while (true){
                System.out.println("等待客户端连接....");
                Socket so = serverSocket.accept();
                System.out.println("一个客户端连接了！");
                //启动处理客户端的交互
                ClientHandler handler = new ClientHandler(so);
                //创建线程对象
                Thread thread = new Thread(handler);
                //启动线程
                thread.start();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        WebServerApplication webServerApplication = new WebServerApplication();
        webServerApplication.start();
    }

}
